package com.hc.exception;

import com.hc.util.JsonResponse;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

//全局异常拦截器,springBoot框架中抛出的异常会被该代码捕获并返回给客户端
@RestControllerAdvice
public class GlobalExceptionHandler {
    // 全局异常拦截
    @ExceptionHandler
    public JsonResponse handlerException(Exception e) {
       //e.printStackTrace();
        //return SaResult.error(e.getMessage());
        JsonResponse jsonResponse = new JsonResponse();
        jsonResponse.setCode(1);
        jsonResponse.setMsg(e.getMessage());
        return  jsonResponse;
    }
}
